<?php
class Agenda extends AppModel {
	var $name = 'Agenda';
	var $validate = array(
		'client_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'user_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $hasMany = array(
		'AgendasSegment' => array(
			'className' => 'AgendasSegment',
			'foreignKey' => 'agenda_id',

		)
	);


        /**
         * Get config Agenda
         * @param int $clientId
         * @param int $profesionalId
         * @param int $agendaId
         * @return arr
         */
        function getAgendaConfig( $clientId=0, $profesionalId=0, $agendaId=0 ){
           
            $arrConfigAgenda = $this->query("SELECT  Segment.day_id, Segment.horario_desde, Segment.horario_hasta, Segment.duracion, 
                                Segment.sobreturno, Segment.max_sobreturnos
				FROM agendas AS Agenda 
                                INNER JOIN agendas_segments AS AgendasSegment ON AgendasSegment.agenda_id = Agenda.id
				INNER JOIN segments AS Segment ON Segment.id = AgendasSegment.segment_id
				WHERE Agenda.client_id = '$clientId' AND Agenda.user_id = '$profesionalId' AND Agenda.id = '$agendaId'
				ORDER BY Segment.day_id, Segment.horario_desde");
            
            foreach($arrConfigAgenda as $key=>$value){
                $arrConfigAgenda[$key]['Segment']['sobreturnos_dados'] = 0;
            }
            
            return $arrConfigAgenda;
        }
}
?>